package com.dg11185.nearshop.activity.welcome;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.Header;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.android.nearshop.R;
import com.dg11185.libs.network.NetClient;
import com.dg11185.libs.network.http.AsyncHttpResponseHandler;
import com.dg11185.libs.network.http.RequestParams;
import com.dg11185.libs.utils.MD5.MD5Utils;
import com.dg11185.libs.utils.print.PrintUtils;
import com.dg11185.nearshop.app.Constants;
import com.dg11185.nearshop.net.NetCacheClient;
import com.dg11185.nearshop.net.request.CountByAreaRequest;
import com.dg11185.nearshop.net.response.CountByAreaResponse;

public class TestFragment extends Fragment{

    // 每次调用只有onCreate和onDestroy不会被重复调用
    Handler handler = new Handler();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.test_fragment_1, null);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);  

    }

    @Override
    public void onResume() {
        super.onResume();
        final String url = "http://192.183.3.181/weixin_v2/commonproject/index.php/AppointmentAPI/getAppointment/point_id/1/date/2014-06-26/sign_key/b6baa33192670d1f988b328a02c802d3";

        final Map<String, String> maps = new HashMap<String, String>();
        maps.put("areaNum", Constants.AREA_NUM);
        maps.put("chshToken", Constants.TOKEN);
        maps.put("chshSign", MD5Utils.getMD5Str(maps, Constants.MD5_key));

        Button button = (Button)getActivity().findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View v) {
                NetClient.client.get(url,new AsyncHttpResponseHandler() {

                    @Override
                    public void onStart() {
                        // called before request is started
                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                        PrintUtils.printo(new String(response));
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
                        PrintUtils.printo(statusCode+"");
                    }

                    @Override
                    public void onRetry(int retryNo) {
                        // called when request is retried
                    }
                });
            }
        });
    }

}
